package cn.edu.jsu.nrs.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import cn.edu.jsu.nrs.dao.ReplyDao;
import cn.edu.jsu.nrs.model.Reply;

@Component
public class ReplyService {

	private ReplyDao replyDao;
	/**
	 * 添加回复
	 * @param reply
	 * @return
	 */
	public boolean addReply(Reply reply){
		Reply reply2=new Reply();
		if (replyDao.save(reply)>0) {
			reply2.setReplyId(replyDao.getLastReply().getReplyId());
			reply.setTbReply(reply2);
			replyDao.update(reply);//更新reply
			return true;
		}else {
			return false;
		}
	}
	/**
	 * 获得所有评论
	 * @return
	 */
	public List<Reply> getReplyList() {
		return replyDao.queryReplies();
	}

	
	/**
	 * 根据新闻ID查询跟贴数
	 * @param newsId
	 * @return
	 */
	public int getReplyCount(int newsId){
		return replyDao.count(newsId);
	}
	
	
	/**
	 * 根据新闻Id获得所有评论
	 * @param newsId
	 * @return
	 */
	public List<Reply> getReplyListByNewsId(int newsId) {
		return replyDao.queryRepliesByNewsId(newsId);
	}

	public List<Reply> getPagingReplyListByNewsId(final int newsId,int beginIndex,final int size){
		return replyDao.queryPagingReplyListByNewsId(newsId, beginIndex, size);
	}
	@Resource
	public void setReplyDao(ReplyDao replyDao) {
		this.replyDao = replyDao;
	}

}
